﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SGS.Logics;
using SGS.Logics.Core;
using System.Net;
using System.Threading;

namespace SGS.Controls
{
    /// <summary>
    /// Interaction logic for Basic.xaml
    /// </summary>
    public partial class Basic : UserControl
    {
        private List<WebBrowser> webBrowsers = new List<WebBrowser>();

        public Basic()
        {
            InitializeComponent();

            this.Init();
        }

        private void Init()
        {
            this.DataContext = Workspace.Instance.BasicData;

            this.InitializeWebBrowsers();
        }

        private void InitializeWebBrowsers()
        {
            this.webBrowsers.Clear();

            for (int i = 0; i < Workspace.Instance.BasicData.AccountCount; i++)
            {
                var browser = new WebBrowser();
                this.webBrowsers.Add(browser);

                TabItem item = new TabItem();
                item.Header = "Account " + i.ToString();
                item.Name = "Account" + i.ToString();
                item.Content = browser;

                Cookie temp1 = new Cookie("KEY" + i.ToString(), "VALUE" + i.ToString(), "/Path/To/My/App", "/");
                bool p = DllHelper.InternetSetCookie("http://web.sanguosha.com/220/play.html?server=5/Path/To/My/App", null, temp1.ToString() + "; expires = Sun, 01-Jan-2014 00:00:00 GMT");

                this.tabControl1.Items.Add(item);

                browser.Navigate("http://web.sanguosha.com/220/play.html?server=5");
            }

            //var th = new Thread(() =>
            //{
            //    var browser = new WebBrowser();
            //    browser.Navigate("http://web.sanguosha.com/220/play.html?server=5");
            //});
            //th.SetApartmentState(ApartmentState.STA);
            //th.Start();
        }
    }
}
